//
//  ALMineViewController.m
//  Ummy.G
//
//  Created by 安林 on 16/9/25.
//  Copyright © 2016年 安林. All rights reserved.
//

#import "ALMineViewController.h"
#import "ALButton.h"
#import "UIBarButtonItem+buttonItem.h"
#import "ALFirstCell.h"
#import "ALSecondCell.h"
#import "ALThirdCell.h"
#import "ALMyPackCell.h"
#import <MJRefresh.h>
#import "ALMessageController.h"
#import "ALSettingController.h"

@interface ALMineViewController ()<UITableViewDataSource,UITableViewDelegate>

//第三个界面的图片、label
@property(nonatomic,strong)NSArray *arrImg1;
@property(nonatomic,strong)NSArray *arrTitle1;

//第四个界面的图片、label
@property(nonatomic,strong)NSArray *arrImg2;
@property(nonatomic,strong)NSArray *arrTitle2;

//第五个界面的图片、label
@property(nonatomic,strong)NSArray *arrImg3;
@property(nonatomic,strong)NSArray *arrTitle3;

@end

@implementation ALMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.delegate = self;
    self.tableView.dataSource =self;
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.tableView.sectionFooterHeight = 5;
    self.tableView.sectionHeaderHeight = 5;
    //设置内边距
    self.tableView.contentInset= UIEdgeInsetsMake(-35, 0, 0, 0);
    
    
    [self addItem];
    
    //第三个界面的图片、label
    _arrImg1 =@[@"mall_of_points",@"icon_paybill_header",@"icon_default_coupon",@"img_member_privilege_ios6"];
    _arrTitle1 =@[@"我的钱包",@"余额",@"抵用券",@"会员卡"];
    
    //第四个界面的图片、label
    _arrImg2 =@[@"icon_tabbar_mine_selected",@"icon_im",@"icon_global_badges_master_official",@"icon_homepage_default"];
    _arrTitle2 =@[@"好友去哪",@"支付帮助",@"会员中心",@"积分商城"];
    
    //第五个界面的图片、label
    _arrImg3 =@[@"icon_phone",@"icon_tabbar_homepage_selected",@"icon_cateye"];
    _arrTitle3 =@[@"客服中心",@"关于美团",@"我要应聘"];
    
    
    //刷新数据
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(addItem)];
    //进来就刷新
    [self.tableView.mj_header beginRefreshing];
    
    
    
}


- (void)addItem{
    
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:ALColor(0, 201, 177)];
    
    //-------设置-------
    UIBarButtonItem *setting = [UIBarButtonItem barButtonItemWith:[UIButton buttonWithType:UIButtonTypeCustom] addTarget:self action:@selector(setClick) andImage:@"icon_mine_account_setting_white" andHighlighted:nil];
    //------消息---------
    UIBarButtonItem *messageR = [UIBarButtonItem barButtonItemWith:[UIButton buttonWithType:UIButtonTypeCustom] addTarget:self action:@selector(MessageClick) andImage:@"icon_navigationItem_message_white" andHighlighted:nil];
    
    self.navigationItem.rightBarButtonItems =@[messageR,setting];
    [self.tableView.mj_header endRefreshing];
}

- (void)setClick{
    
    ALSettingController *set = [[ALSettingController alloc]init];
    UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:set];
    [self presentViewController:na animated:YES completion:nil];
}

- (void)MessageClick{
    
    ALMessageController *message = [[ALMessageController alloc]init];
    UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:message];
    [self presentViewController:na animated:YES completion:nil];
}


#pragma mark tableView Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 5;
}


#pragma mark 创建每个组有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section==0) {
        return 1;
    }else if (section==1){
        return 1;
    }else if (section==2){
        return 4;
    }else if (section==3){
        return 4;
    }else{
        return 3;
    }
}

#pragma mark 加载每一个xib
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *ummy = nil;
    if (indexPath.section==0) {
        static NSString *ID = @"first";
        ALFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [ALFirstCell loadALFirstCell];
        }
        
        //当点击tableView时无颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        ummy =cell;
    }else if (indexPath.section==1){
        static NSString *ID = @"second";
        ALSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell==nil) {
            cell = [ALSecondCell loadALSecondCell];
        }
        ummy = cell;
    }else if (indexPath.section ==2){
        static NSString *ID = @"third";
        ALThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [ALThirdCell loadALThirdCell];
        }
        
        cell.titleLabel.text = self.arrTitle1[indexPath.row];
        cell.ImgView.image = [UIImage imageNamed:self.arrImg1[indexPath.row]];
        
        //当点击tableView时无颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        ummy = cell;
    }else if (indexPath.section==3){
        static NSString *ID = @"third";
        ALThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [ALThirdCell loadALThirdCell];
        }
        cell.titleLabel.text = self.arrTitle2[indexPath.row];
        cell.ImgView.image = [UIImage imageNamed:self.arrImg2[indexPath.row]];
        
        //当点击tableView时无颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        ummy = cell;
    }else{
        static NSString *ID = @"third";
        ALThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [ALThirdCell loadALThirdCell];
        }
         cell.titleLabel.text = self.arrTitle3[indexPath.row];
         cell.ImgView.image = [UIImage imageNamed:self.arrImg3[indexPath.row]];
        
        //当点击tableView时无颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        ummy = cell;
    }
    return ummy;
}

#pragma mark 设置每一组的行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        return 120;
    }else if (indexPath.section==1){
        return 120;
    }else if (indexPath.section==2){
        return 45;
    }else if (indexPath.section==3){
        return 45;
    }else{
        return 45;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 2 && indexPath.row == 0) {
        //我的钱包
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/account/points/?mtt=1.help%2Fselfservice.0.0.itz3cl2z"]];
    }else if (indexPath.section == 2 && indexPath.row == 1){
        //余额
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/account/points/?mtt=1.help%2Fselfservice.0.0.itz3cl2z"]];
    }else if (indexPath.section == 2 && indexPath.row == 2){
        //抵用券
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/account/points/?mtt=1.help%2Fselfservice.0.0.itz3cl2z"]];
    }else if (indexPath.section == 2 && indexPath.row == 3){
        //会员卡
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/account/points/?mtt=1.help%2Fselfservice.0.0.itz3cl2z"]];
    
    }else if (indexPath.section == 3 && indexPath.row == 0){
        //好友去哪
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/account/points/?mtt=1.help%2Fselfservice.0.0.itz3cl2z"]];
    }else if (indexPath.section == 3 && indexPath.row == 1){
        //支付帮助
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://i.meituan.com/help/pay?f=ios&ci=1&lat=39.98345504672791&lng=116.3180332149903&msid=48E2B810-805D-4821-9CDD-D5C9E01BC98A2015-07-07-09-47438&token=p19ukJltGhla4y5Jryb1jgCdKjsAAAAAsgAAADHFD3UYGxaY2FlFPQXQj2wCyCrhhn7VVB-KpG_U3-clHlvsLM8JRrnZK35y8UU3DQ&userid=10086&utm_campaign=AgroupBgroupD100Fab_chunceshishuju__a__a___ab_pindaoshenyang__a__leftflow___ab_gxhceshi__nostrategy__leftflow___ab_gxhceshi0202__b__a___ab_pindaochangsha__a__leftflow___ab_xinkeceshi__b__leftflow___ab_waimaiwending__a__a___ab_gxtest__gd__leftflow___ab_gxh_82__nostrategy__leftflow___ab_b_food_57_purepoilist_extinfo__a__a___i_group_5_2_deallist_poitype__d__d___ab_i_group_5_3_poidetaildeallist__a__b___ab_pindaoquxincelue0630__b__b1___ab_waimaizhanshi__b__b1___a20141120nanning__m1__leftflow___b1junglehomepagecatesort__b__leftflow___ab_i_group_5_5_onsite__b__b___ab_i_group_5_6_searchkuang__a__leftflowGmore&utm_content=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&utm_medium=iphone&utm_source=AppStore&utm_term=5.7&uuid=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&version_name=5.7"]];
        
    }else if (indexPath.section == 3 && indexPath.row == 2){
        //会员中心
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/account/points/?mtt=1.help%2Fselfservice.0.0.itz3cl2z"]];
    }else if (indexPath.section == 3 && indexPath.row == 3){
        //积分商城
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/account/points/?mtt=1.help%2Fselfservice.0.0.itz3cl2z"]];
    }else if (indexPath.section == 4 && indexPath.row == 0){
        //客服中心
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/help/selfservice?mtt=1.index%2Ffloornew.0.0.itxy3eaq"]];
    }else if (indexPath.section == 4 && indexPath.row == 1){
         //关于美团
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.meituan.com/about/?mtt=1.help%2Fapi.0.0.itz3t1ji"]];
    }else{
        //我要应聘
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://i.meituan.com/help/jobs?ci=1&f=iphone&msid=48E2B810-805D-4821-9CDD-D5C9E01BC98A2015-07-07-09-47438&token=p19ukJltGhla4y5Jryb1jgCdKjsAAAAAsgAAADHFD3UYGxaY2FlFPQXQj2wCyCrhhn7VVB-KpG_U3-clHlvsLM8JRrnZK35y8UU3DQ&userid=10086&utm_campaign=AgroupBgroupD100Fab_chunceshishuju__a__a___ab_pindaoshenyang__a__leftflow___ab_gxhceshi__nostrategy__leftflow___ab_gxhceshi0202__b__a___ab_pindaochangsha__a__leftflow___ab_xinkeceshi__b__leftflow___ab_waimaiwending__a__a___ab_gxtest__gd__leftflow___ab_gxh_82__nostrategy__leftflow___ab_b_food_57_purepoilist_extinfo__a__a___i_group_5_2_deallist_poitype__d__d___ab_i_group_5_3_poidetaildeallist__a__b___ab_pindaoquxincelue0630__b__b1___ab_waimaizhanshi__b__b1___a20141120nanning__m1__leftflow___b1junglehomepagecatesort__b__leftflow___ab_i_group_5_5_onsite__b__b___ab_i_group_5_6_searchkuang__a__leftflowGmore&utm_content=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&utm_medium=iphone&utm_source=AppStore&utm_term=5.7&uuid=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&version_name=5.7&lat=39.98345504672791&lng=116.3180332149903"]];
       
    }
}

@end